package com.hyts.serialize.binary.fst;

import com.hyts.serialize.bean.FstBean;
import com.hyts.serialize.factory.FstBeanFactory;
import com.hyts.serialize.binary.BinarySerializeHandler;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.serialize.handler.fst
 * author:Libo/Alex
 * create-date:2019-06-21 22:57
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: fst序列化处理器
 */
public class FstSerializeHandler extends BinarySerializeHandler<FstBean,FstBean> {


    @Override
    public BinarySerializeHandler<FstBean, FstBean> build() {
        setResult(FstBeanFactory.builder().build().create());
        return this;
    }

    @Override
    public BinarySerializeHandler<FstBean, FstBean> build(FstBean param) {
        setResult(FstBeanFactory.builder().build().create(param));
        return this;
    }

    @Override
    public <T> T deserialize(byte[] byteData, Class<T> clazzType) {
        return (T) getResult().getFstConfiguration().asObject(byteData);
    }

    @Override
    public <T> T serialize(T byteData, Class<T> clazzType) {
        throw new UnsupportedOperationException("不支持此方法-protostuff专属使用");
    }

    @Override
    public byte[] serialize(Object value) {
        return getResult().getFstConfiguration().asByteArray(value);
    }

    @Override
    public Object deserialize(byte[] param) {
        return getResult().getFstConfiguration().asObject(param);
    }
}
